﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Deparment_ShowNote : System.Web.UI.Page
{
    public string strTitle, strContent, strAddDate;
    private string Notid,_accountid;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumDeparment);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            _accountid = _Account.AccountId.ToString();

            if (SysFun.ToTrim(Request.QueryString["Notid"]) != "")
            {
                Notid = SysFun.PasswordDecrypt(Request.QueryString["Notid"].Trim());
                ShowNote(Notid, 1);
            }
            if (SysFun.ToTrim(Request.QueryString["DiaryId"]) != "")
            {
                Notid = SysFun.PasswordDecrypt(Request.QueryString["DiaryId"].Trim());
                ShowNote(Notid, 2);
            }
            if (SysFun.ToTrim(Request.QueryString["EmailId"]) != "")
            {
                Notid = SysFun.PasswordDecrypt(Request.QueryString["EmailId"].Trim());
                ShowNote(Notid, 3);
            }
            if (SysFun.ToTrim(Request.QueryString["BoxID"]) != "")
            {
                Notid = SysFun.PasswordDecrypt(Request.QueryString["BoxID"].Trim());
                UpdateEmail(Notid);
            }
            if (SysFun.ToTrim(Request.QueryString["duty_lowerid"]) != "")
            {
                Notid = SysFun.PasswordDecrypt(Request.QueryString["duty_lowerid"].Trim());
                ShowNote(Notid, 4);
            }
            if (SysFun.ToTrim(Request.QueryString["WithinInfoId"]) != "")
            {
                Notid = SysFun.PasswordDecrypt(Request.QueryString["WithinInfoId"].Trim());
                ShowNote(Notid, 5);
            }
        }
    }

    private void ShowNote(string id,int nsort)
    {
       
        if (!IsPostBack)
        {
            if (id != "" && id != null)
            {
                string sql="";
                if (nsort == 1)//新闻
                {
                     sql = "select Notid,Title,AddDate,Content,DOWNLOAD from Note where Notid=" + id;
                }
                if (nsort==2) //日志
                {
                    sql = "select Title,addDate,Content,'' as DOWNLOAD from Diary where DiaryId=" + id;
                }
                if (nsort == 3) //文件
                {
                    sql = "select Title,addDate,Content,uploadfile,downLoadUrl as DOWNLOAD from D_Email where EmailId=" + id;
                }
                if (nsort == 4) //政策法规
                {
                    sql = "select * from D_duty_lower where info_sort=2 and duty_lowerid=" + id;
                }
                if (nsort == 5) //部门内部信息
                {
                    sql = "select * from WithinInfo where info_sort=1 and WithinInfoId=" + id;
                }
                Db db = new Db();
                try
                {
                    System.Data.IDataReader dr;
                    dr = db.DataReader(sql);
                    if (dr.Read())
                    {
                        strTitle = dr["Title"].ToString();
                        strContent = dr["Content"].ToString().Replace("\r\n", "<br>");
                        strAddDate = Convert.ToDateTime(dr["AddDate"].ToString()).ToShortDateString();
                        string strDOWNURL = SysFun.ToTrim(dr["DOWNLOAD"].ToString());
                        if (strDOWNURL != "")
                        {
                            Label1.Text = "";
                            foreach (string strId in strDOWNURL.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                if (nsort == 1)
                                {
                                    Label1.Text += "&nbsp;&nbsp;<a class=9tw href='../UploadFile/" + strId + "' style='cursor:hand;' ><font size='2'>" + strId.Substring(0, strId.IndexOf(".")) + "</font></a>&nbsp;&nbsp;&nbsp;&nbsp;<br>";
                                }
                                else
                                {
                                    Label1.Text += "&nbsp;&nbsp;<a class=9tw href='DupdateFile/" + strId + "' style='cursor:hand;' ><font size='2'>" + dr["uploadfile"].ToString() + "</font></a>&nbsp;&nbsp;&nbsp;&nbsp;<br>";
                                }
                            }
                        }
                        else
                        {
                            Label1.Visible = false;
                        }

                    }
                    dr.Close();
                    dr.Dispose();
                    db.Close();
                }
                catch
                {
                    db.Close();
                }
            }
        }
    }

    private void UpdateEmail(string Notid)
    {
        string stt = "update D_BoxEmail set Readflag=1,Readtime=getdate() where BoxID=" + Notid + " and Accoumtid_Send= "+_accountid;
        Db dd = new Db();
        dd.Command(stt);
        dd.Close();
    }
}
